package com.liy.jiagou.gateway.utils;


import com.liy.jiagou.gateway.filter.AuthorizeFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.jwt.JwtHelper;
import org.springframework.security.jwt.crypto.sign.MacSigner;



/**
 *
 *
 *
 */
public class JWTUtil {

    private static final Logger log = LoggerFactory.getLogger(JWTUtil.class);

    public static final long TOKEN_EXPIRE_TIME = 7200 * 1000;


    // n. 发行人
    private static final String ISSUER = "liy";


    // jwt_secret

    /**
     * 校验Token
     * @param token
     * @param secretKey
     * @return
     */
    public static void verifyToken(String token, String secretKey) {

        // 使用的是默认算法 HMACSHA256 加密的 MacSigner
        //  public class MacSigner implements SignerVerifier {
        //	private static final String DEFAULT_ALGORITHM = "HMACSHA256";

        MacSigner macSignerVerifier = new MacSigner(secretKey);

        Jwt jwt = JwtHelper.decodeAndVerify(token, macSignerVerifier);

        String claims = jwt.getClaims();

        String encoded = jwt.getEncoded();

        log.error("-----------------  claims --------------->   " +  claims);
        log.error("-----------------  encoded --------------->   " +  encoded);

    }





}
